Missouri state income tax#

This notebook shows how Missouri’s state income tax, including credits, operates holistically.

Examples#

1 or 2 person household , $1,000/month in rent, under 65, cohabitating.#

from policyengine_us import IndividualSim
import pandas as pd
import plotly.express as px

LIGHT_GRAY = "#F5F5F5"
GRAY = "#BDBDBD"
BLUE = "#5091cc"
LIGHT_BLUE = "lightblue"
DARK_BLUE = "darkblue"


def make_tax_under_65(adults, children):
    sim = IndividualSim(year=2021)
    sim.add_person(name="head", age=25, rent=0)
    members = ["head"]
    if adults == 2:
        sim.add_person(name="spouse", age=25)
        members += ["spouse"]
    for i in range(children):
        child = "child{}".format(i)
        sim.add_person(name=child, age=6)
        members += [child]
    sim.add_tax_unit(name="tax_unit", members=members, premium_tax_credit=0)
    sim.add_household(name="household", members=members, state_code="MO")
    sim.vary("employment_income", max=100_000, step=100)
    employment_income = sim.calc("employment_income")[0]
    mo_income_tax = sim.calc("mo_income_tax")[0].round()
    mtr = sim.deriv("mo_income_tax", "employment_income", wrt_target="head")
    return pd.DataFrame(
        dict(
            employment_income=employment_income,
            mo_income_tax=mo_income_tax,
            mtr=mtr,
            adults=adults,
            children=str(children),
        )
    )


# Make a table of state taxes for different numbers of adults and children.
l = []
for adults in range(1, 3):
    for children in range(0, 4):
        l.append(make_tax_under_65(adults, children))

df = pd.concat(l)

LABELS = dict(
    employment_income="Employment income",
    mo_income_tax="Missouri income tax",
    mtr="Marginal tax rate",
    adults="Adults",
    children="Children",
)

COLOR_MAP = {"0": GRAY, "1": LIGHT_BLUE, "2": BLUE, "3": DARK_BLUE}

fig = px.line(
    df,
    "employment_income",
    "mo_income_tax",
    color="children",
    animation_frame="adults",
    labels=LABELS,
    title="Missouri income tax",
    color_discrete_map=COLOR_MAP,
)
fig.update_layout(
    xaxis_tickformat="$,",
    yaxis_tickformat="$,",
    plot_bgcolor="white",
    xaxis_gridcolor=LIGHT_GRAY,
    yaxis_gridcolor=LIGHT_GRAY,
)
fig.show()
fig = px.line(
    df,
    "employment_income",
    "mtr",
    color="children",
    animation_frame="adults",
    labels=LABELS,
    title="Marginal tax rate for a Missouri household",
    color_discrete_map=COLOR_MAP,
)
fig.update_layout(
    xaxis_tickformat="$,",
    yaxis_tickformat=".1%",
    yaxis_range=[-0.2, 0.2],
    plot_bgcolor="white",
    xaxis_gridcolor=LIGHT_GRAY,
    yaxis_gridcolor=LIGHT_GRAY,
)

1 or 2 person household , $1,000/month in rent, over 65, cohabitating.#

from policyengine_us import IndividualSim
import pandas as pd
import plotly.express as px

LIGHT_GRAY = "#F5F5F5"
GRAY = "#BDBDBD"
BLUE = "#5091cc"
LIGHT_BLUE = "lightblue"
DARK_BLUE = "darkblue"


def make_tax_over_65(adults, children):
    sim = IndividualSim(year=2022)
    sim.add_person(name="head", age=75, rent=12_000)
    members = ["head"]
    if adults == 2:
        sim.add_person(name="spouse", age=75)
        members += ["spouse"]
    for i in range(children):
        child = "child{}".format(i)
        sim.add_person(name=child, age=6)
        members += [child]
    sim.add_tax_unit(name="tax_unit", members=members, premium_tax_credit=0)
    sim.add_household(name="household", members=members, state_code="MO")
    sim.vary("employment_income", max=100_000, step=100)
    employment_income = sim.calc("employment_income")[0]
    mo_income_tax = sim.calc("mo_income_tax")[0].round()
    mtr = sim.deriv("mo_income_tax", "employment_income", wrt_target="head")
    return pd.DataFrame(
        dict(
            employment_income=employment_income,
            mo_income_tax=mo_income_tax,
            mtr=mtr,
            adults=adults,
            children=str(children),
        )
    )


# Make a table of state taxes for different numbers of adults and children.
l = []
for adults in range(1, 3):
    for children in range(0, 4):
        l.append(make_tax_over_65(adults, children))

df = pd.concat(l)

LABELS = dict(
    employment_income="Employment income",
    mo_income_tax="Missouri income tax for ",
    mtr="Marginal tax rate",
    adults="Adults",
    children="Children",
)

COLOR_MAP = {"0": GRAY, "1": LIGHT_BLUE, "2": BLUE, "3": DARK_BLUE}

fig = px.line(
    df,
    "employment_income",
    "mo_income_tax",
    color="children",
    animation_frame="adults",
    labels=LABELS,
    title="Missouri income tax",
    color_discrete_map=COLOR_MAP,
)
fig.update_layout(
    xaxis_tickformat="$,",
    yaxis_tickformat="$,",
    plot_bgcolor="white",
    xaxis_gridcolor=LIGHT_GRAY,
    yaxis_gridcolor=LIGHT_GRAY,
)
fig.show()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/individual_sim.py:261, in IndividualSim.calc(self, var, period, target, index, map_to, reform)
    260 try:
--> 261     result = self.simulation.calculate(var, period)
    262 except:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:707, in Simulation._run_formula(self, variable, population, period)
    706     for subtracted_variable in subtracts_list:
--> 707         values = values - self.calculate(
    708             subtracted_variable, period, map_to=variable.entity.key
    709         )
    710 return values

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:687, in Simulation._run_formula(self, variable, population, period)
    686     for added_variable in adds_list:
--> 687         values = values + self.calculate(
    688             added_variable, period, map_to=variable.entity.key
    689         )
    690 if variable.subtracts is not None:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/states/mo/tax/income/credits/property_tax/mo_property_tax_credit.py:35, in mo_property_tax_credit.formula(tax_unit, period, parameters)
     34 po_rate = p.phase_out.rate
---> 35 net_income = tax_unit("mo_ptc_net_income", period)
     36 excess_income = max_(0, net_income - po_start)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/states/mo/tax/income/credits/property_tax/mo_ptc_net_income.py:18, in mo_ptc_net_income.formula(tax_unit, period, parameters)
     17 def formula(tax_unit, period, parameters):
---> 18     gross_income = tax_unit("mo_ptc_gross_income", period)
     19     income_offset = tax_unit("mo_ptc_income_offset", period)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/states/mo/tax/income/credits/property_tax/mo_ptc_gross_income.py:39, in mo_ptc_gross_income.formula(tax_unit, period, parameters)
     35 pa_sources = parameters(
     36     period
     37 ).gov.states.mo.tax.income.credits.property_tax.public_assistance_types
     38 public_assistance_income = tax_unit.sum(
---> 39     add(person, period, pa_sources)  # line 6
     40 )
     41 # compute nonbusiness capital losses in PTC gross income (line 7)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:223, in add(entity, period, variables, options)
    209 """Sums a list of variables.
    210 
    211 Args:
   (...)
    221     ArrayLike: The result of the operation.
    222 """
--> 223 return for_each_variable(
    224     entity, period, variables, agg_func="add", options=options
    225 )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:179, in for_each_variable(entity, period, variables, agg_func, group_agg_func, options)
    178 if variable_entity.key == entity.entity.key:
--> 179     values = entity(variable, period, options=options)
    180 elif variable_entity.is_person:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi.py:16, in ssi.formula(person, period, parameters)
     15     return 0
---> 16 return max_(0, person("uncapped_ssi", period))

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/uncapped_ssi.py:13, in uncapped_ssi.formula(person, period, parameters)
     12 def formula(person, period, parameters):
---> 13     amount = person("ssi_amount_if_eligible", period)
     14     meets_resource_test = person("meets_ssi_resource_test", period)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi_amount_if_eligible.py:16, in ssi_amount_if_eligible.formula(person, period, parameters)
     13 ssi = parameters(period).gov.ssa.ssi.amount
     14 return (
     15     where(
---> 16         person("ssi_claim_is_joint", period),
     17         ssi.couple,
     18         ssi.individual,
     19     )
     20     * MONTHS_IN_YEAR
     21 )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi_claim_is_joint.py:12, in ssi_claim_is_joint.formula(person, period, parameters)
     11 eligible = person("is_ssi_aged_blind_disabled", period)
---> 12 both_eligible = person.marital_unit.sum(eligible) == 2
     13 income_is_deemed = (
     14     person("ssi_income_deemed_from_ineligible_spouse", period) > 0
     15 )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/projector.py:28, in Projector.__getattr__.<locals>.projector_function(*args, **kwargs)
     27 result = reference_attr(*args, **kwargs)
---> 28 return self.transform_and_bubble_up(result)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/projector.py:37, in Projector.transform_and_bubble_up(self, result)
     36 def transform_and_bubble_up(self, result):
---> 37     transformed_result = self.transform(result)
     38     if self.parent is None:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/entity_to_person_projector.py:19, in EntityToPersonProjector.transform(self, result)
     18 def transform(self, result: ArrayLike) -> ArrayLike:
---> 19     return self.reference_entity.project(result)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/group_population.py:335, in GroupPopulation.project(self, array, role)
    334 def project(self, array: ArrayLike, role: Role = None) -> ArrayLike:
--> 335     self.check_array_compatible_with_entity(array)
    336     self.entity.check_role_validity(role)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:60, in Population.check_array_compatible_with_entity(self, array)
     59 if not self.count == array.size:
---> 60     raise ValueError(
     61         "Input {} is not a valid value for the entity {} (size = {} != {} = count)".format(
     62             array, self.entity.key, array.size, self.count
     63         )
     64     )

ValueError: Input [1. 0. 0. ... 0. 0. 1.] is not a valid value for the entity marital_unit (size = 4002 != 4004 = count)

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/individual_sim.py:264, in IndividualSim.calc(self, var, period, target, index, map_to, reform)
    263 try:
--> 264     result = self.sim.calculate_add(var, period)
    265 except:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:600, in Simulation.calculate_add(self, variable_name, period, decode_enums)
    594     raise ValueError(
    595         "Unable to sum constant variable '{}' over period {}: only variables defined daily, monthly, or yearly can be summed over time.".format(
    596             variable.name, period
    597         )
    598     )
--> 600 return sum(
    601     self.calculate(variable_name, sub_period)
    602     for sub_period in period.get_subperiods(variable.definition_period)
    603 )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:601, in <genexpr>(.0)
    594     raise ValueError(
    595         "Unable to sum constant variable '{}' over period {}: only variables defined daily, monthly, or yearly can be summed over time.".format(
    596             variable.name, period
    597         )
    598     )
    600 return sum(
--> 601     self.calculate(variable_name, sub_period)
    602     for sub_period in period.get_subperiods(variable.definition_period)
    603 )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:707, in Simulation._run_formula(self, variable, population, period)
    706     for subtracted_variable in subtracts_list:
--> 707         values = values - self.calculate(
    708             subtracted_variable, period, map_to=variable.entity.key
    709         )
    710 return values

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:687, in Simulation._run_formula(self, variable, population, period)
    686     for added_variable in adds_list:
--> 687         values = values + self.calculate(
    688             added_variable, period, map_to=variable.entity.key
    689         )
    690 if variable.subtracts is not None:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/states/mo/tax/income/credits/property_tax/mo_property_tax_credit.py:35, in mo_property_tax_credit.formula(tax_unit, period, parameters)
     34 po_rate = p.phase_out.rate
---> 35 net_income = tax_unit("mo_ptc_net_income", period)
     36 excess_income = max_(0, net_income - po_start)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/states/mo/tax/income/credits/property_tax/mo_ptc_net_income.py:18, in mo_ptc_net_income.formula(tax_unit, period, parameters)
     17 def formula(tax_unit, period, parameters):
---> 18     gross_income = tax_unit("mo_ptc_gross_income", period)
     19     income_offset = tax_unit("mo_ptc_income_offset", period)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/states/mo/tax/income/credits/property_tax/mo_ptc_gross_income.py:39, in mo_ptc_gross_income.formula(tax_unit, period, parameters)
     35 pa_sources = parameters(
     36     period
     37 ).gov.states.mo.tax.income.credits.property_tax.public_assistance_types
     38 public_assistance_income = tax_unit.sum(
---> 39     add(person, period, pa_sources)  # line 6
     40 )
     41 # compute nonbusiness capital losses in PTC gross income (line 7)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:223, in add(entity, period, variables, options)
    209 """Sums a list of variables.
    210 
    211 Args:
   (...)
    221     ArrayLike: The result of the operation.
    222 """
--> 223 return for_each_variable(
    224     entity, period, variables, agg_func="add", options=options
    225 )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:179, in for_each_variable(entity, period, variables, agg_func, group_agg_func, options)
    178 if variable_entity.key == entity.entity.key:
--> 179     values = entity(variable, period, options=options)
    180 elif variable_entity.is_person:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi.py:16, in ssi.formula(person, period, parameters)
     15     return 0
---> 16 return max_(0, person("uncapped_ssi", period))

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/uncapped_ssi.py:13, in uncapped_ssi.formula(person, period, parameters)
     12 def formula(person, period, parameters):
---> 13     amount = person("ssi_amount_if_eligible", period)
     14     meets_resource_test = person("meets_ssi_resource_test", period)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi_amount_if_eligible.py:16, in ssi_amount_if_eligible.formula(person, period, parameters)
     13 ssi = parameters(period).gov.ssa.ssi.amount
     14 return (
     15     where(
---> 16         person("ssi_claim_is_joint", period),
     17         ssi.couple,
     18         ssi.individual,
     19     )
     20     * MONTHS_IN_YEAR
     21 )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    483 self._check_for_cycle(variable.name, period)
--> 484 array = self._run_formula(variable, population, period)
    486 # If no result, use the default value and cache it

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi_claim_is_joint.py:12, in ssi_claim_is_joint.formula(person, period, parameters)
     11 eligible = person("is_ssi_aged_blind_disabled", period)
---> 12 both_eligible = person.marital_unit.sum(eligible) == 2
     13 income_is_deemed = (
     14     person("ssi_income_deemed_from_ineligible_spouse", period) > 0
     15 )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/projector.py:28, in Projector.__getattr__.<locals>.projector_function(*args, **kwargs)
     27 result = reference_attr(*args, **kwargs)
---> 28 return self.transform_and_bubble_up(result)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/projector.py:37, in Projector.transform_and_bubble_up(self, result)
     36 def transform_and_bubble_up(self, result):
---> 37     transformed_result = self.transform(result)
     38     if self.parent is None:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/entity_to_person_projector.py:19, in EntityToPersonProjector.transform(self, result)
     18 def transform(self, result: ArrayLike) -> ArrayLike:
---> 19     return self.reference_entity.project(result)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/group_population.py:335, in GroupPopulation.project(self, array, role)
    334 def project(self, array: ArrayLike, role: Role = None) -> ArrayLike:
--> 335     self.check_array_compatible_with_entity(array)
    336     self.entity.check_role_validity(role)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:60, in Population.check_array_compatible_with_entity(self, array)
     59 if not self.count == array.size:
---> 60     raise ValueError(
     61         "Input {} is not a valid value for the entity {} (size = {} != {} = count)".format(
     62             array, self.entity.key, array.size, self.count
     63         )
     64     )

ValueError: Input [1. 0. 0. ... 0. 0. 1.] is not a valid value for the entity marital_unit (size = 4002 != 4004 = count)

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
Cell In[3], line 44
     42 for adults in range(1, 3):
     43     for children in range(0, 4):
---> 44         l.append(make_tax_over_65(adults, children))
     46 df = pd.concat(l)
     48 LABELS = dict(
     49     employment_income="Employment income",
     50     mo_income_tax="Missouri income tax for ",
   (...)
     53     children="Children",
     54 )

Cell In[3], line 27, in make_tax_over_65(adults, children)
     25 sim.vary("employment_income", max=100_000, step=100)
     26 employment_income = sim.calc("employment_income")[0]
---> 27 mo_income_tax = sim.calc("mo_income_tax")[0].round()
     28 mtr = sim.deriv("mo_income_tax", "employment_income", wrt_target="head")
     29 return pd.DataFrame(
     30     dict(
     31         employment_income=employment_income,
   (...)
     36     )
     37 )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/individual_sim.py:266, in IndividualSim.calc(self, var, period, target, index, map_to, reform)
    264         result = self.sim.calculate_add(var, period)
    265     except:
--> 266         result = self.simulation.calculate_divide(var, period)
    267 if (
    268     target is not None
    269     and target not in self.situation_data[entity.plural]
    270 ):
    271     map_to = self.get_entity(target).key

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:637, in Simulation.calculate_divide(self, variable_name, period, decode_enums)
    633     return (
    634         self.calculate(variable_name, period=computation_period) / 12.0
    635     )
    636 elif period.unit == periods.YEAR:
--> 637     return self.calculate(variable_name, period)
    639 raise ValueError(
    640     "Unable to divide the value of '{}' to match period {}.".format(
    641         variable_name, period
    642     )
    643 )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    318 self.tracer.record_calculation_start(
    319     variable_name, period, self.branch_name
    320 )
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:
    325         result = result.decode_to_str()

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    482 try:
    483     self._check_for_cycle(variable.name, period)
--> 484     array = self._run_formula(variable, population, period)
    486     # If no result, use the default value and cache it
    487     if array is None:
    488         # Check if the variable has a previously defined value

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:707, in Simulation._run_formula(self, variable, population, period)
    705             values = 0
    706         for subtracted_variable in subtracts_list:
--> 707             values = values - self.calculate(
    708                 subtracted_variable, period, map_to=variable.entity.key
    709             )
    710     return values
    712 if self.trace and not isinstance(
    713     self.tax_benefit_system.parameters, TracingParameterNodeAtInstant
    714 ):
    715     # Soft-recast

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    318 self.tracer.record_calculation_start(
    319     variable_name, period, self.branch_name
    320 )
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:
    325         result = result.decode_to_str()

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    482 try:
    483     self._check_for_cycle(variable.name, period)
--> 484     array = self._run_formula(variable, population, period)
    486     # If no result, use the default value and cache it
    487     if array is None:
    488         # Check if the variable has a previously defined value

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:687, in Simulation._run_formula(self, variable, population, period)
    685     values = 0
    686     for added_variable in adds_list:
--> 687         values = values + self.calculate(
    688             added_variable, period, map_to=variable.entity.key
    689         )
    690 if variable.subtracts is not None:
    691     if isinstance(variable.subtracts, str):

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    318 self.tracer.record_calculation_start(
    319     variable_name, period, self.branch_name
    320 )
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:
    325         result = result.decode_to_str()

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    482 try:
    483     self._check_for_cycle(variable.name, period)
--> 484     array = self._run_formula(variable, population, period)
    486     # If no result, use the default value and cache it
    487     if array is None:
    488         # Check if the variable has a previously defined value

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    722     array = formula(population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/states/mo/tax/income/credits/property_tax/mo_property_tax_credit.py:35, in mo_property_tax_credit.formula(tax_unit, period, parameters)
     33 po_step = p.phase_out.step
     34 po_rate = p.phase_out.rate
---> 35 net_income = tax_unit("mo_ptc_net_income", period)
     36 excess_income = max_(0, net_income - po_start)
     37 po_steps = np.ceil(excess_income / po_step)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    130     return self.simulation.calculate_divide(
    131         variable_name, period, **calculate_kwargs
    132     )
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    318 self.tracer.record_calculation_start(
    319     variable_name, period, self.branch_name
    320 )
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:
    325         result = result.decode_to_str()

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    482 try:
    483     self._check_for_cycle(variable.name, period)
--> 484     array = self._run_formula(variable, population, period)
    486     # If no result, use the default value and cache it
    487     if array is None:
    488         # Check if the variable has a previously defined value

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    722     array = formula(population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/states/mo/tax/income/credits/property_tax/mo_ptc_net_income.py:18, in mo_ptc_net_income.formula(tax_unit, period, parameters)
     17 def formula(tax_unit, period, parameters):
---> 18     gross_income = tax_unit("mo_ptc_gross_income", period)
     19     income_offset = tax_unit("mo_ptc_income_offset", period)
     20     return max_(0, gross_income - income_offset)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    130     return self.simulation.calculate_divide(
    131         variable_name, period, **calculate_kwargs
    132     )
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    318 self.tracer.record_calculation_start(
    319     variable_name, period, self.branch_name
    320 )
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:
    325         result = result.decode_to_str()

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    482 try:
    483     self._check_for_cycle(variable.name, period)
--> 484     array = self._run_formula(variable, population, period)
    486     # If no result, use the default value and cache it
    487     if array is None:
    488         # Check if the variable has a previously defined value

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    722     array = formula(population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/states/mo/tax/income/credits/property_tax/mo_ptc_gross_income.py:39, in mo_ptc_gross_income.formula(tax_unit, period, parameters)
     34 # compute person-level public assistance included in PTC gross income
     35 pa_sources = parameters(
     36     period
     37 ).gov.states.mo.tax.income.credits.property_tax.public_assistance_types
     38 public_assistance_income = tax_unit.sum(
---> 39     add(person, period, pa_sources)  # line 6
     40 )
     41 # compute nonbusiness capital losses in PTC gross income (line 7)
     42 losses = ["short_term_capital_losses", "long_term_capital_losses"]

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:223, in add(entity, period, variables, options)
    203 def add(
    204     entity: Population,
    205     period: Period,
    206     variables: List[str],
    207     options: List[str] = None,
    208 ):
    209     """Sums a list of variables.
    210 
    211     Args:
   (...)
    221         ArrayLike: The result of the operation.
    222     """
--> 223     return for_each_variable(
    224         entity, period, variables, agg_func="add", options=options
    225     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:179, in for_each_variable(entity, period, variables, agg_func, group_agg_func, options)
    177 variable_entity = entity.entity.get_variable(variable).entity
    178 if variable_entity.key == entity.entity.key:
--> 179     values = entity(variable, period, options=options)
    180 elif variable_entity.is_person:
    181     values = group_agg_func(
    182         entity.members(variable, period, options=options)
    183     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    130     return self.simulation.calculate_divide(
    131         variable_name, period, **calculate_kwargs
    132     )
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    318 self.tracer.record_calculation_start(
    319     variable_name, period, self.branch_name
    320 )
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:
    325         result = result.decode_to_str()

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    482 try:
    483     self._check_for_cycle(variable.name, period)
--> 484     array = self._run_formula(variable, population, period)
    486     # If no result, use the default value and cache it
    487     if array is None:
    488         # Check if the variable has a previously defined value

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    722     array = formula(population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi.py:16, in ssi.formula(person, period, parameters)
     14 if parameters(period).gov.ssa.ssi.abolish_ssi:
     15     return 0
---> 16 return max_(0, person("uncapped_ssi", period))

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    130     return self.simulation.calculate_divide(
    131         variable_name, period, **calculate_kwargs
    132     )
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    318 self.tracer.record_calculation_start(
    319     variable_name, period, self.branch_name
    320 )
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:
    325         result = result.decode_to_str()

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    482 try:
    483     self._check_for_cycle(variable.name, period)
--> 484     array = self._run_formula(variable, population, period)
    486     # If no result, use the default value and cache it
    487     if array is None:
    488         # Check if the variable has a previously defined value

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    722     array = formula(population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/uncapped_ssi.py:13, in uncapped_ssi.formula(person, period, parameters)
     12 def formula(person, period, parameters):
---> 13     amount = person("ssi_amount_if_eligible", period)
     14     meets_resource_test = person("meets_ssi_resource_test", period)
     15     eligible = person("is_ssi_eligible_individual", period)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    130     return self.simulation.calculate_divide(
    131         variable_name, period, **calculate_kwargs
    132     )
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    318 self.tracer.record_calculation_start(
    319     variable_name, period, self.branch_name
    320 )
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:
    325         result = result.decode_to_str()

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    482 try:
    483     self._check_for_cycle(variable.name, period)
--> 484     array = self._run_formula(variable, population, period)
    486     # If no result, use the default value and cache it
    487     if array is None:
    488         # Check if the variable has a previously defined value

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    722     array = formula(population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi_amount_if_eligible.py:16, in ssi_amount_if_eligible.formula(person, period, parameters)
     12 def formula(person, period, parameters):
     13     ssi = parameters(period).gov.ssa.ssi.amount
     14     return (
     15         where(
---> 16             person("ssi_claim_is_joint", period),
     17             ssi.couple,
     18             ssi.individual,
     19         )
     20         * MONTHS_IN_YEAR
     21     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
    130     return self.simulation.calculate_divide(
    131         variable_name, period, **calculate_kwargs
    132     )
    133 else:
--> 134     return self.simulation.calculate(
    135         variable_name, period, **calculate_kwargs
    136     )

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:323, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
    318 self.tracer.record_calculation_start(
    319     variable_name, period, self.branch_name
    320 )
    322 try:
--> 323     result = self._calculate(variable_name, period)
    324     if isinstance(result, EnumArray) and decode_enums:
    325         result = result.decode_to_str()

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:484, in Simulation._calculate(self, variable_name, period)
    482 try:
    483     self._check_for_cycle(variable.name, period)
--> 484     array = self._run_formula(variable, population, period)
    486     # If no result, use the default value and cache it
    487     if array is None:
    488         # Check if the variable has a previously defined value

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:724, in Simulation._run_formula(self, variable, population, period)
    722     array = formula(population, period)
    723 else:
--> 724     array = formula(population, period, parameters_at)
    726 return array

File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi_claim_is_joint.py:12, in ssi_claim_is_joint.formula(person, period, parameters)
     10 def formula(person, period, parameters):
     11     eligible = person("is_ssi_aged_blind_disabled", period)
---> 12     both_eligible = person.marital_unit.sum(eligible) == 2
     13     income_is_deemed = (
     14         person("ssi_income_deemed_from_ineligible_spouse", period) > 0
     15     )
     16     return both_eligible | income_is_deemed

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/projector.py:28, in Projector.__getattr__.<locals>.projector_function(*args, **kwargs)
     26 def projector_function(*args, **kwargs):
     27     result = reference_attr(*args, **kwargs)
---> 28     return self.transform_and_bubble_up(result)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/projector.py:37, in Projector.transform_and_bubble_up(self, result)
     36 def transform_and_bubble_up(self, result):
---> 37     transformed_result = self.transform(result)
     38     if self.parent is None:
     39         return transformed_result

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/entity_to_person_projector.py:19, in EntityToPersonProjector.transform(self, result)
     18 def transform(self, result: ArrayLike) -> ArrayLike:
---> 19     return self.reference_entity.project(result)

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/group_population.py:335, in GroupPopulation.project(self, array, role)
    334 def project(self, array: ArrayLike, role: Role = None) -> ArrayLike:
--> 335     self.check_array_compatible_with_entity(array)
    336     self.entity.check_role_validity(role)
    337     if role is None:

File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:60, in Population.check_array_compatible_with_entity(self, array)
     58 def check_array_compatible_with_entity(self, array: numpy.ndarray) -> None:
     59     if not self.count == array.size:
---> 60         raise ValueError(
     61             "Input {} is not a valid value for the entity {} (size = {} != {} = count)".format(
     62                 array, self.entity.key, array.size, self.count
     63             )
     64         )

ValueError: Input [1. 0. 0. ... 0. 0. 1.] is not a valid value for the entity marital_unit (size = 4002 != 4004 = count)
fig = px.line(
    df,
    "employment_income",
    "mtr",
    color="children",
    animation_frame="adults",
    labels=LABELS,
    title="Marginal tax rate for a Missouri household",
    color_discrete_map=COLOR_MAP,
)
fig.update_layout(
    xaxis_tickformat="$,",
    yaxis_tickformat=".1%",
    yaxis_range=[-0.2, 0.2],
    plot_bgcolor="white",
    xaxis_gridcolor=LIGHT_GRAY,
    yaxis_gridcolor=LIGHT_GRAY,
)
fig.show()